#ifndef _HEAD_H_
#define _HEAD_H_

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <linux/fb.h>
#include <fcntl.h>
#include <math.h>

typedef unsigned char u8_t;
typedef unsigned short u16_t;
typedef unsigned int u32_t;

typedef struct 
{
	int w;				  /* width */
	int h;				  /* high */
	int bpp;			  /* bits per pixel */
	u8_t *fbmem;
}fb_info;

typedef struct point 
{
	int x;
	int y;
}point;

typedef struct 
{
	int x;
	int y;
	int button;
}mouse_event_t;

typedef struct
{
	point point_t;
	int is_set;
	u32_t chess;

}point_info;

#define FB_DEVICE "/dev/fb0"
#define MOUSE_DEVICE "/dev/input/mice"
#define C_WIDTH  10
#define C_HEIGHT 17

#define TRUE 1
#define FALSE 0

#define T___     0XFFFFFFFF
#define BORD     0x0
#define X___     0xFFFF

//extern u32_t player_flag; /* 玩家*/
int m_i;
int m_j;

static unsigned long cursor_pixel[C_WIDTH * C_HEIGHT] = {
  BORD, T___, T___, T___, T___, T___, T___, T___, T___, T___,
  BORD, BORD, T___, T___, T___, T___, T___, T___, T___, T___,
  BORD, X___, BORD, T___, T___, T___, T___, T___, T___, T___,
  BORD, X___, X___, BORD, T___, T___, T___, T___, T___, T___,
  BORD, X___, X___, X___, BORD, T___, T___, T___, T___, T___,
  BORD, X___, X___, X___, X___, BORD, T___, T___, T___, T___,
  BORD, X___, X___, X___, X___, X___, BORD, T___, T___, T___,
  BORD, X___, X___, X___, X___, X___, X___, BORD, T___, T___,
  BORD, X___, X___, X___, X___, X___, X___, X___, BORD, T___,
  BORD, X___, X___, X___, X___, X___, X___, X___, X___, BORD,
  BORD, X___, X___, X___, X___, X___, BORD, BORD, BORD, BORD,
  BORD, X___, X___, BORD, X___, X___, BORD, T___, T___, T___,
  BORD, X___, BORD, T___, BORD, X___, X___, BORD, T___, T___,
  BORD, BORD, T___, T___, BORD, X___, X___, BORD, T___, T___,
  T___, T___, T___, T___, T___, BORD, X___, X___, BORD, T___,
  T___, T___, T___, T___, T___, BORD, X___, X___, BORD, T___,
  T___, T___, T___, T___, T___, T___, BORD, BORD, T___, T___
};
static unsigned long save_cursor[C_WIDTH * C_HEIGHT];
static point_info save[17][17] = {{0, 0}, 0, 0};

/* Initialize framebuffer */
extern int init(fb_info *my_fb);

/* draw point */
extern int fb_point(fb_info my_fb, int x, int y, u32_t color);

/* draw circle */
extern int fb_circle(fb_info my_fb, int x, int y, int len, u32_t color);

/* draw straight */
extern int fb_str_row(fb_info my_fb, int x, int y, int len, u32_t color);
extern int fb_str_col(fb_info my_fb, int x, int y, int len, u32_t color);

/* draw square */
extern int fb_square(fb_info my_fb, int x, int y, int len, int width, u32_t color);

extern int fb_diagonal(fb_info my_fb, point point_t1, point point_t2, u32_t color);

extern int fb_chess_map(fb_info my_fb, int x, int y, int len, u32_t color);



/*  mouse  */
extern int fb_init_mouse(int *fd);

extern int fb_drawcursor(fb_info my_fb, int x, int y);

extern int mouse_parse(const u8_t *buf, mouse_event_t* mevent);

extern int fb_savecursor(fb_info my_fb, int x, int y);

extern int fb_restorecursor(fb_info my_fb, int x, int y);

extern int fb_chess_play(fb_info my_fb);

//extern int flag_change(int flag);

extern u32_t color_change(u32_t color);

extern int save_chess(fb_info my_fb);

extern int fb_chessgo(fb_info my_fb, int x, int y);
#endif
